package com.umakr.demo.controller;

import com.umakr.demo.model.Kaostpye;
import com.umakr.demo.model.KaostpyeKecheng;
import com.umakr.demo.model.Kecheng;
import com.umakr.demo.service.KaostypeKechengService;
import com.umakr.demo.service.KechengService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import sun.plugin.javascript.navig.LinkArray;

import java.util.List;

/**
 * Created by yangliu on 2017/8/23.
 */
@Controller
@RequestMapping("/KaostypeKechengController")
public class KaostypeKechengController {
    @Autowired
    KechengService kechengService;

    @Autowired
    KaostypeKechengService kaostypeKechengService;

    @RequestMapping("/showKaostypeKecheng")
    public  String showKaostypeKecheng(){
        return "StudentManage/kaostypekecheng";
    }

    @RequestMapping("/kaostypeDate")
    @ResponseBody
    public List<Kaostpye> kaostpyeDate(){
        List<Kaostpye> list = kaostypeKechengService.showKaostype();
        return list;
    }

    @RequestMapping("/kechengDate")
    @ResponseBody
    public  List<Kecheng> kechengDate(){
        List<Kecheng> list = kechengService.showAll();
        return list;
    }

    @RequestMapping("/kaostypeShowKecheng")
    @ResponseBody
    public List<Kecheng> kaostypeShowKecheng(Long kaoslid){
        List<Kecheng> list = kaostypeKechengService.kaostypeShowKecheng(kaoslid);
        return list;
    }

    @RequestMapping("/allSelectedKecheng")
    @ResponseBody
    public void allSelectedKecheng(Long kaoslid, @RequestParam(value = "str[]",required = false) String str[]){
//        删除所有的数据
        System.out.println(kaoslid+"0000000"+str);

        kaostypeKechengService.deleteAll(kaoslid);
        for(int i=0;i<str.length;i++){
            KaostpyeKecheng kaostpyeKecheng = new KaostpyeKecheng(kaoslid,Long.parseLong(str[i]));
            kaostypeKechengService.addAll(kaostpyeKecheng);
        }
    }



}
